﻿using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;

namespace ITextSharpPDF
{
    class Program
    {
        private static DataTable CreateDemoData()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("ID"));
            dataTable.Columns.Add(new DataColumn("Name"));
            dataTable.Columns.Add(new DataColumn("Sex"));
            dataTable.Columns.Add(new DataColumn("Age"));
            dataTable.Columns.Add(new DataColumn("Phone"));
            dataTable.Columns.Add(new DataColumn("Address"));

            for (int i = 0; i < 20; i++)
            {
                dataTable.Rows.Add(i, $"第{i}行", i * new Random().Next(10));
            }

            return dataTable;
        }

        public static void Main()
        {
            PrintPDF generate = new PrintPDF();
            generate.Test();
            //Sharp0901._Main();
            //FontTest._Main();

            //foreach (var item in CreateDemoData().Columns)
            //{
            //    Console.WriteLine(item.ToString());
            //}

            return;
            string imgPath = AppDomain.CurrentDomain.BaseDirectory + "\\logo.jpg";
            //字体设定，c:\windows\fonts\kaiu.ttf，中文楷体
            BaseFont bfchinese = BaseFont.CreateFont(@"C:\Windows\Fonts\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont chinese = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont simsunFont = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            Font ChFont = new Font(simsunFont, 24);
            Font ChFont_blue = new Font(bfchinese, 24, Font.NORMAL, new Color(51, 0, 153));
            Font ChFont_msg = new Font(chinese, 24, Font.NORMAL, Color.RED);


            Document document = new Document(PageSize.A4.Rotate());
            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream("FontTest.pdf", FileMode.Create));
            //加密
            //pdfWriter.SetEncryption(PdfWriter.STRENGTH128BITS, "1234", "1244", PdfWriter.ALLOW_COPY | PdfWriter.AllowPrinting);
            document.Open();
            document.AddAuthor("zero");
            document.Add(new Paragraph("放大是否飒飒的", ChFont));//调用重载函数 public Paragraph(string str, Font font);将字体传进去
            document.Add(new Paragraph("放大是否飒飒的", ChFont_blue));//调用重载函数 public Paragraph(string str, Font font);将字体传进去
            document.Add(new Paragraph("放大是否飒飒的", ChFont_msg));//调用重载函数 public Paragraph(string str, Font font);将字体传进去
            Image img = Image.GetInstance(imgPath);
            document.Add(img);
            //Header footer = new Header();
            document.AddHeader("footer", "this is footer");
            //pdfWriter.Dispose();
            //pdfWriter.Close();
            document.Close();
        }
    }
}
